<%@ page language="java" import="java.util.*"
	contentType="text/html;charset=utf-8" errorPage="ErrorPage.jsp"%>
<%@ page import="java.sql.*" import="com.zm.jdbc.AccessDb"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">

		<title>My JSP 'AccessDb.jsp' starting page</title>

		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		
		<script>
		
		     function getHttpRequest(){
		        if(XMLHttpRequest){
		         return new XMLHttpRequest();
		        }else if(ActiveXObject)
		            return new ActiveXObject("Microsoft.XMLHTTP");
		     }
		    function deleteinfo(a){
		     var result=confirm("删除？");
		     if(result==true){
		          var request=getHttpRequest();
		          request.onreadystatechange=function(){
		                if(request.readyState==4){
		                   if(request.status==200){
		                        var text=request.responseText;
		                        if(text.indexOf("deleted")!=-1)
		                          
		                              a.parentNode.parentNode.style.display="none";
		                        }
		                   }
		           }
		          request.open("GET",a.href+"&flag=asyn",true);
		           request.send(null);
		        }
		         return false; 
		      }
		      
		      
		  
		
		
		</script>

	</head>


	<body>


		<%-- 加载驱动，连接数据库 --%>
		<%
        AccessDb db=null;
        if(application.getAttribute("accessdb")==null){
              db=new AccessDb();
              application.setAttribute("accessdb",db);
        }
        else 
            db=(AccessDb)application.getAttribute("accessdb");
        
       
            ResultSet result=db.executeQuery("SELECT * FROM account");    
    
             int num=result.getMetaData().getColumnCount();
         
         
         %>

		<table bgcolor="#eeffee" border="2" width="400px">
			<tr>
				<%   for(int i=1;i<=num;i++){   %>
				<th><%=result.getMetaData().getColumnName(i)%></th>
				<% }          %>
				<th>change</th>
				<th>delete</th>
			</tr>

			<%while(result.next()){%>
			<tr>
				<td><%=result.getString(1)%></td>
				<td><%=result.getString(2)%></td>
				<td><%=result.getInt(3) %></td>
				<td><%=result.getString(4) %></td>
				<td><%=result.getString(5) %></td>
				<td><a href="ChangeJsp.jsp?name=<%=result.getString(1)%>&passwd=<%=result.getString(2)%>&age=<%=result.getInt(3)%>&sex=<%=result.getString(4)%>&telnum=<%=result.getString(5)%>">修改</a></td>
				<td><a href="servlet/TestServlet?name=<%=result.getString(1)%>&method=delete" onclick="return deleteinfo(this)">删除</a></td>
			</tr>
			<% }%>





		</table>

		This is my JSP page.
		<br>
	</body>
</html>
